export interface GlobalFilterDataType {
  conditions: any[];
  dateCondition: Record<string, any>;
}

export enum GraphType {
  NUMBER = 1,
  BAR,
  AREA,
  PIE,
  GAUGE,
  COMPUTED,
  TEXT
}

export enum TimeFrameType {
  DAY = 'day',
  WEEK = 'week',
  MONTH = 'month',
  QUARTER = 'quarter',
  YEAR = 'year'
}

export const statisticalPeriodOption = [
  { label: '当日', value: 'day' },
  { label: '当周', value: 'week' },
  { label: '当月', value: 'month' },
  { label: '当季', value: 'quarter' },
  { label: '当年', value: 'year' },
  { label: '最近', value: 'recent' },
  { label: '周至今', value: 'week_to_now' },
  { label: '月至今', value: 'month_to_now' },
  { label: '年至今', value: 'year_to_now ' }
];

export const statisticalPeriodUnitOption = [
  { label: '日', value: 'day' },
  { label: '周', value: 'week' },
  { label: '月', value: 'month' },
  { label: '季', value: 'quarter' },
  { label: '年', value: 'year' }
];

export const numFormatOption = [
  { label: '个', value: 'GE' },
  { label: '万', value: 'WAN' },
  { label: '亿', value: 'YI' },
  { label: '百分比', value: 'PERCENT' }
];

export const defaultGlobalModel: Record<string, any> = {
  chosenMetricsIds: [],
  conditions: [],
  dateCondition: null
};

// 根据图表类型构造初始配置数据
export const getDefaultConfigModel = (type: GraphType, timeframe = 'day') => {
  let base = {
    metricsSetting: {
      metricsId: null,
      metricsName: '',
      metricsConditions: [],
      numberFormat: 'GE',
      rela: 'AND',
      statisticalPeriod: {
        offset: 1,
        timeUnit: timeframe,
        type: timeframe
      }
    },
    compares: [],
    type: GraphType.NUMBER,
    dataTime: '',
    result: null
  };
  let dateCondition = {
    dateMode: 'BEFORE',
    offset: 1,
    fixDate: '',
    timeUnit: timeframe
  };
  let timeFrequency = {
    offset: 1,
    timeUnit: timeframe
  };
  let distributeDimId = '';
  let distributeDimName = '';
  let targetVal = null;
  let phaseTargetVal = null;
  let progessTrack = {
    enabled: true,
    startDate: '',
    endDate: '',
    timeUnit: timeframe
  };
  switch (type) {
    case GraphType.NUMBER:
      return { ...base, dateCondition };
    case GraphType.AREA:
      return { ...base, timeFrequency };
    case GraphType.BAR:
      return { ...base, dateCondition, distributeDimId, distributeDimName };
    case GraphType.PIE:
      return { ...base, dateCondition, distributeDimId, distributeDimName };
    case GraphType.GAUGE:
      return {
        ...base,
        dateCondition,
        targetVal,
        phaseTargetVal,
        progessTrack
      };
    case GraphType.NUMBER:
      return { ...base, dateCondition };
    default:
      return { ...base, dateCondition };
  }
};
